#ifndef DEVICE_H
#define DEVICE_H

#include <QObject>
#include <QThread>
#include "modbus.h"
#include "dockwidget2.h"
#include <QTimer>
#include <QByteArray>

class Device:public QObject
{
    Q_OBJECT
public:
    Device();
    ~Device();
    void SlotsInit();
    void SlotsInitWhenDeviceCreated();
    void CreateDevice();
    void OpenDevice();
    void StartTimer();
    void StopTimer();
    void StartCommunication(int timeout,int start,int end);
    DockWidget2* GetDockWidget();
    QThread mThread;
    Modbus  *modbus=nullptr;
    QTimer  *timer=nullptr;
    unsigned char deviceAddress=1;
    int timeout=1000;
    RecvBuf recvBuf;
    long frameCount=0;
    int frameIndex=0;//轮询发送的ID
    bool isRunning=false;
signals:
    void To_CreateDevice();
    void To_StartTimer();
    void To_OpenDevice();
    void To_StopTimer();
    void To_WriteData(QByteArray,int);
    void To_ShowRecvData(QByteArray);
public slots:
    void Slots_CreateDevice();
    void Slots_TimeOut();
    void Slots_StartTimer();
    void Slots_OpenDevice();
    void Slots_StopTimer();
    void WriteReadFunction(QByteArray sendData,int timeout);
};

#endif // DEVICE_H
